<template>
  <div>
    <ConTitle :topTitle="topTitle"/>

    <!--  显示表格数据-->
    <el-table :data="accountList" cell-style="text-align: center" header-cell-style="text-align: center" style="width: 100%">
      <el-table-column type="index" label="序号" width="100"></el-table-column>
      <el-table-column prop="account" label="账号"></el-table-column>
      <el-table-column prop="username" label="用户名称"></el-table-column>
      <el-table-column prop="type" label="类型">
        <template slot-scope="scope">
          {{ scope.row.type | accountType }}
        </template>
      </el-table-column>
      <el-table-column prop="cTime" label="创建时间">
        <template slot-scope="scope">
          {{scope.row.cTime | format}}
        </template>
      </el-table-column>
      <el-table-column prop="uTime" label="更新时间">
        <template slot-scope="scope">
          {{scope.row.uTime | format}}
        </template>
      </el-table-column>
      <el-table-column prop="desc" label="描述"></el-table-column>
      <el-table-column
          label="操作"
          width="150">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" icon="el-icon-edit" circle></el-button>
          <el-button type="danger" icon="el-icon-delete" circle></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import ConTitle from "@/components/ConTitle";
import {$accountList} from "@/api";

export default {
  components: {
    ConTitle,
  },
  name: "accountList",
  data() {
    return {
      accountList:[],
      topTitle: {
        type: "子账号",
        text: "子账号列表",
        msg: "展示当前组织下的所有子账号，可修改改子账号信息或删除子账号。"
      },
    }
  },
  filters: {
    //账号类型的过滤器
    accountType(value) {
      return value==1 ? "超级管理员" : (value==3 ? "管理员" : "观察员");
    },
    //时间戳转日期时间
    format(value){
      //数字小于10 在数字前面加0
      function addZero(num){
        return num >= 10 ? num : "0" + num;
      }
      var time = new Date(parseInt(value));
      var y = time.getFullYear();
      var m = addZero(time.getMonth() + 1);
      var d = addZero(time.getDate());
      return `${y}-${m}-${d}`;
    }
  },
  mounted() {
    $accountList().then(res =>{
      console.log(res.data.data);
      this.accountList = res.data.data;
    });
  },
}
</script>

<style scoped lang="scss">

</style>